var Path = require('path')
var FS = require('fs')
var file_util = require('./file_util')

var project_path = process.argv[2] //构建目录
var platform = process.argv[3] // 平台
var isBefore = process.argv[4] // 构建之前处理


function copyFile(beforePath, projectPath) {
	var stat
	var subpaths = FS.readdirSync(beforePath),
		subpath;;
	for (var i = 0; i < subpaths.length; ++i) {
		if (subpaths[i][0] === '.') {
			continue;
		}
		subpath = Path.join(beforePath, subpaths[i]);
		stat = FS.statSync(subpath);
		var exportPath = Path.join(projectPath, subpaths[i])
		if (stat.isFile()) {
			file_util.copy(subpath, exportPath)
		} else {
			file_util.copyDir(subpath, exportPath)
		}
	}
}



function copy(project_path, platform, isBefore) {
	var beforePath = Path.join(project_path, 'platform', platform, 'before')
	var afterPath = Path.join(project_path, 'platform', platform, 'after')
	if (isBefore == 1)
		copyFile(beforePath, project_path)
	else
		copyFile(afterPath, project_path)

}

if (project_path) {
	copy(project_path, platform, isBefore)
}
module.exports.copy = copy;
